package mall.service;

import mall.core.jdbc.Page;
import mall.entity.Book;
import mall.repository.BookRepository;
import mall.entity.Book;
import java.util.List;

/**
 * @author xf07b1
 * @wechat xf07b1
 * @description
 */
public class BookService {
    private final BookRepository bookRepository = new BookRepository();

    public void add(Book book) {
        bookRepository.insert(book);
    }

    public void deleteById(int id) {
        bookRepository.deleteById(id);
    }

    public void update(Book book) {
        bookRepository.update(book);
    }

    public Book getById(int id) {
        return bookRepository.selectById(id);
    }

    public Page<Book> page(Page<Book> page, Book book) {
        Integer total = bookRepository.count(book);
        List<Book> list = bookRepository.selectList(book, page.getOffset(), page.getPageSize());
        page.setTotal(total);
        page.setList(list);
        return page;
    }
}
